import { StorageKey } from '../common/Key';
import { GameData } from '../game/GameData';
import { GameState } from '../game/GameState';
import { EnergyMgr } from '../../resources/components/energy/EnergyMgr';
import { TaskMgr } from '../game/TaskMgr';
cc.Class({
    extends: require('BaseScene'),

    properties: {
        labVer: cc.Label,
    },

    onLoad() {
        this._super();

    },

    start() {
        G.partner.sendEvent('场景', { '类型': 'boot' });
        this.allStep = 2;
        this.step = 0;
        this.index = 0;
        this._boot();
    },

    onEnable() {
        this._super();

    },

    onDisable() {
        this._super();

    },

    _boot() {
        wx.tmSDK.init({
            hideRequestLog: false,
            appVersion: '1.0.0'
        });

        wx.tmSDK.getAppJSONConfig('banner_ad_key').then((res) => {
            G.config.addCoin = res.addCoin;
        });


        GameData.init();
        GameState.init();
        EnergyMgr.init();
        TaskMgr.init();
        this._openCollision();
        this._preloadScene();
        // this._loadScene();
        this._loadJson();
        G.game.loadScene('SceneGame');
        return;
    },

    _openCollision() {
        if (!G.config.OPENCOLLISION) {
            return;
        }
        var manager = cc.director.getCollisionManager();
        manager.enabled = true;
    },

    _loadJson(cb) {
        // G.json.addItem('HeroData');
        // G.json.addItem('MonsterData');
        // G.json.startLoad(() => {
        //     // console.log(G.json.getJson('HeroData'))
        //     cb && cb();
        // });
    },

    _preloadScene() {
        // G.game.preloadScene('SceneHome', () => {
        //     this.step++;
        //     this._loadScene();
        // });
        // G.game.preloadScene('SceneGame', () => {
        //     this.step++;
        //     this._loadScene();
        // });
    },

    _loadScene() {
        if (this.step >= this.allStep || true) {
            cc.tween(this.node)
                .delay(1)
                .to(1, { opacity: 0 })
                .call(() => {
                    G.data.setItem(StorageKey.FIRST_LAUNCH, true);
                    G.game.loadScene('SceneHome');
                })
                .start();
        }
    },
});
